//
//  catch.swift
//  DemoUI
//  异常
//  Created by 白瑾浩 on 2022/6/16.
//

import Foundation
class catchClass{
    static func netRequest(status : Int) throws -> Void {
            
      let obStatus = status
            
      if obStatus == 401 {
        throw NetError.networkError
      } else if obStatus == 402 {
        throw NetError.authError
      } else {
        print("all right ！")
      }
    }
    
    static func test(){
        do {
          
          try netRequest(status: 401)
            
          noThrowErrorCanDoSomeThing()

        } catch NetError.networkError {
          handleNetworkError()
        } catch NetError.authError {
          handleNetworkError()
        } catch {
          print("其他错误")
        }
        
    }
    
    static func noThrowErrorCanDoSomeThing () {
            print("没有抛出错误，继续执行")
        }
        
    static func handleNetworkError() -> Void {
            print("网络错误，请检查网络")
        }
    
    
    
}

fileprivate enum NetError : Error {
  case authError
  case networkError
}
